<?php
    $appid = "wx873faf7512b61145";  
    $secret = "c1efbe6e57bd6cb78ad29ecec928295c";  
    $code = $_GET["code"];

    $get_token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$secret.'&code='.$code.'&grant_type=authorization_code';

    $ch = curl_init();  
    curl_setopt($ch,CURLOPT_URL,$get_token_url);  
    curl_setopt($ch,CURLOPT_HEADER,0);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );  
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);  
    $res = curl_exec($ch);  
    curl_close($ch);  
    $json_obj = json_decode($res,true);   
    //根据openid和access_token查询用户信息  
    $access_token = $json_obj['access_token'];  
    $openid = $json_obj['openid'];
    $link=mysqli_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS);
    mysqli_select_db($link,"app_formtest1");
    $sql="select * from weixin_students where student_weixin_id='$openid'";
	$r=mysqli_query($link,$sql);
    $row=mysqli_fetch_object($r);
    $academy_id = $row->academy_id;
    switch($academy_id)
    {
        case 1:
        header("location:http://v.xiumi.us/board/v5/20M0G/5182145");     //数学与计算机学院
        break;
        case 2:
        header("location:http://v.xiumi.us/board/v5/20M0G/5314213");    //外国语学院
        break;
        case 3:
        header("location:http://v.xiumi.us/board/v5/20M0G/5311870");   //纺织科学与工程学院
        break;
        default:
        
    }
?>
